package com.road.crawler.meizitu.crawler;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.geccocrawler.gecco.annotation.Attr;
import com.geccocrawler.gecco.annotation.Href;
import com.geccocrawler.gecco.annotation.Html;
import com.geccocrawler.gecco.annotation.HtmlField;
import com.geccocrawler.gecco.spider.HtmlBean;

/**
 * @Description :
 * @FileName: Picture.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年3月29日 上午11:48:52
 * @Version:V1.00
 */
public class Picture implements HtmlBean {

	private static final long serialVersionUID = 1L;
	
	/**
	 * 获取小括号内容的正则表达式
	 */
	private static final Pattern parentheses = Pattern.compile("(?<=\\()(\\S+)(?=\\))");

	@Attr("title")
	@HtmlField(cssPath = "div > a")
	private String alt;

	@Attr("href")
	@HtmlField(cssPath = "div > a")
	private String href;

	@Attr("style")
	@HtmlField(cssPath = "div > a > p")
	private String thumbnail;
	
	@Html
	@HtmlField(cssPath = "div > div > p.chapter > a")
	private String newestTitle;
	
	@Href
	@HtmlField(cssPath = "div > div > p.chapter > a")
	private String newestUrl;

	public String getAlt() {
		return alt;
	}

	public void setAlt(String alt) {
		this.alt = alt;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	public String getThumbnail() {
		return thumbnail;
	}

	public String getNewestTitle() {
		return newestTitle;
	}

	public void setNewestTitle(String newestTitle) {
		this.newestTitle = newestTitle;
	}

	public String getNewestUrl() {
		return newestUrl;
	}

	public void setNewestUrl(String newestUrl) {
		this.newestUrl = newestUrl;
	}

	public void setThumbnail(String thumbnail) {
		Matcher matcher = parentheses.matcher(thumbnail);
		if (matcher.find()) {
			this.thumbnail = matcher.group();
		} else {
			this.thumbnail = thumbnail;
		}
	}

}
